public class Category {
	public String term { get; set; }
	public String scheme { get; set; }
	public String label { get; set; }
 
	public Category() {
	}
	public Category(XmlStreamReader reader) {
		String tagName = 'category';
		while (reader.hasNext()) {
			if (reader.getEventType() == XmlTag.END_ELEMENT) {
				if (tagName == 'category') {
					return;
				}
			} else if (reader.getEventType() == XmlTag.CHARACTERS) {
            } else if (reader.getEventType() == XmlTag.START_ELEMENT) {
            	tagName = reader.getLocalName();
				handleAttributes(reader, tagName);
			}
			reader.next();			
		} 
	}
	
	public String toAPP() {
		String output = '<category ';
		if (term != null) output += 'term="' + term + '" ';
		if (scheme != null) output += 'scheme="' + scheme + '" ';
		if (label != null) output += 'label="' + label + '" ';
		output += ' />\n';
		return output;
	}
	
	private void handleAttributes(XmlStreamReader reader, String tagName) {
		for (integer i=0; i<reader.getAttributeCount(); i++) {
      		String name = reader.getAttributeLocalName(i);
       		String value = reader.getAttributeValueAt(i);
       		if (tagName == 'category') {
       			if (name == 'label') {
       				label = value;
       			} else if (name == 'scheme') {
       				scheme = value;
       			} else if (name == 'term') {
       				term = value;
       			}
       		}
        }
       
	}
	
}